package com.zjs.controller;

import com.github.pagehelper.PageInfo;
import com.zjs.common.bean.PageQuery;
import com.zjs.common.bean.ResponseResult;
import com.zjs.pojo.SysAuthRole;
import com.zjs.service.Impl.SysAuthRoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.management.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @类名： SysAuthRoleController
 * @说明： TODO
 * @作者：SS 苏帅出品
 * @时间：2019/12/14 17:00
 * @版本：1.0
 */
@Controller
@RequestMapping(value = "role")
public class SysAuthRoleController {

    @Autowired
    SysAuthRoleServiceImpl sysAuthRoleService;

    @RequestMapping(value = "findAllPage.action")
    @ResponseBody
    public Map<String,Object> findAll(PageQuery query){
        Map<String,Object> map=new HashMap<>();

        PageInfo<SysAuthRole> allRole = sysAuthRoleService.findAllRole(query);

        map.put("total",allRole.getTotal());
        map.put("rows",allRole.getList());

        return map;
    }

    @RequestMapping(value = "findAddRolePage.action")
    public String findAddRolePage(){

        return "admin/role_add";
    }


    @RequestMapping(value = "saveRole.action")
    @ResponseBody
    public ResponseResult saveRole(SysAuthRole role,String ids){

        //添加角色
        int i = sysAuthRoleService.saveRole(role, ids);


        if (i>0){

            return new ResponseResult(true,null);

        }

        return new ResponseResult(false,null);
    }


    @RequestMapping(value = "findAllRoles.action")
    @ResponseBody
    public List<SysAuthRole> findAllSysAuthRole(){

        return  sysAuthRoleService.findAllRoles();
    }
}
